<?php
namespace App\Repos;

use App\Models\Product;

use Carbon\Carbon;
use DB;


class ProductRepo 
{
    
    public static function create($data)
    {            
        Product::create($data);        
        return true;
    } 

    public static function update($id,$data)
    {
       
        Product::where(['id'=>$id])->update($data);
                
       
    }   
  

    public static function getListPages($where=[],$num=10,$fields=['*']) 
    {
    	$query = Product::query();        
       
        
        $query = $query->select($fields)->where($where);
        $list  = $query->orderBy('created_at','asc')
        					->paginate($num);
        return $list;					
    }

    public static  function destroy($id)
    {
        $rs['status'] = false;
        

        $flag = Product::destroy($id);
        if($flag) {
            $rs['status'] = true;
        }
        return $rs;


    }

   

 

    public static function find($where,$fields= ['*'])
    {
        $data = Product::select($fields)
                        ->where($where)
                        ->first();
        return $data;
    }

   

    


    // 修改产品上下架状态
    public static function ChangeStatus($id,$data)
    {
        $updateData['on_sale'] = $data['status'];
        self::update(['id'=>$id],$updateData);
        AdminHandlerLogRepo::create('Product',$id,$data);
        //dd($adminHandlerLog);       
        //event(new AdminHanderEvent($adminHandlerLog));

    }
}
